package com.yksj.healthtalk.comm;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yksj.healthtalk.services.CoreService;
import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.ui.app.AppManager;

public class BaseFragmentActivity extends FragmentActivity {
	
	public Button titleLeftBtn;
	public Button titleRightBtn;
	public Button titleRightBtn2;
	public TextView titleTextV;
	public RelativeLayout title;
	
	public void initTitle(){
		titleLeftBtn = (Button)findViewById(R.id.title_back);
		titleRightBtn = (Button)findViewById(R.id.title_right);
		titleTextV = (TextView)findViewById(R.id.title_lable);
		titleRightBtn2 = (Button)findViewById(R.id.title_right2);
		title = (RelativeLayout)findViewById(R.id.title_root);
	}
	
	public final void setBackBtn(String text,OnClickListener listener){
		titleLeftBtn.setBackgroundDrawable(null);
		titleLeftBtn.setText(text);
		titleLeftBtn.setOnClickListener(listener);
	}
	
	public final void setBlackColor(TextView textView){
		if(textView != null){
			textView.setTextColor(getResources().getColor(R.color.black));
		}
	}
	
	public final void setTitle(String txt){
		titleTextV.setText(txt);
	}
	
	public final void setRight(String txt,OnClickListener listener){
		if(titleRightBtn2 == null)return;
		titleRightBtn2.setText(txt);
		titleRightBtn2.setVisibility(View.VISIBLE);
		titleRightBtn2.setOnClickListener(listener);
	}
	
	public final void setRightBtnYellowBg(String text,OnClickListener listener){
		if(titleRightBtn2 == null)return;
		titleRightBtn2.setVisibility(View.VISIBLE);
		titleRightBtn2.setText(text);
		titleRightBtn2.setOnClickListener(listener);
	}
	
	public final void setRightMore(OnClickListener listener){
		titleRightBtn2.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_more));
		titleRightBtn2.setVisibility(View.VISIBLE);
		titleRightBtn2.setOnClickListener(listener);
	}
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		AppManager.getInstance().addStack(this);
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		AppManager.getInstance().finishActivity(this);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		Intent intent =new Intent(this,CoreService.class);
		intent.setAction(CoreService.ACTION_FRAME_VIEW_GONE);
		startService(intent);
	}
	
}
